home *** CD-ROM | disk | FTP | other *** search
/ CD Ware Multimedia 1995 May / cd Ware (Juegos) Epimundo.iso / DOS / PRGMMING / CPP100.ZIP / CPPLHELP.C < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-22  |  10.6 KB  |  284 lines

  1. /*****************************************************************************/
  2. /*       (C) 1993,1994 R. NADE - M. GRANDCHAMP - All Rights Reserved         */
  3. /*****************************************************************************/
  4. /*    This source-code is NOT public domain nor Freeware, this is part of    */
  5. /*              'The C Programming Package' which is Shareware.              */
  6. /*   If you use this code, please register and get a free Full-VGA version   */
  7. /*****************************************************************************/
  8.                             /*-------------------*
  9.                              *     CPPLHELP.C    *
  10.                              *    help manager   *
  11.                              *    text version.  *
  12.                              *-------------------*/
  13.  
  14.  /* Included Files */
  15.  # include <stdio.h>
  16.  # include <io.h>
  17.  # include <dos.h>
  18.  # include <SYS\stat.h>
  19.  # include <conio.h>
  20.  # include <fcntl.h>
  21.  
  22.  /* Global Variables */
  23.  extern int bm,i,j,k,l,m,n,x,xm,y,ym,z,beginningfile,endfile,pagemaxi;
  24.  extern int colour1,colour2,colour3,colour4,colour5,pfhelp;
  25.  extern long dephelp,depbeginning;
  26.  extern unsigned char c1,nc1[],trashcan[],trashhelp[],trashelhelp[];
  27.  extern unsigned char trashret[],work[];
  28.  
  29.  /*----------------*
  30.   * OPEN HELP FILE *
  31.   *----------------*/
  32.   int open_help_file(offset)
  33.     int offset;
  34.     {
  35.       /* Get the access path to the help file */
  36.       strcpy(trashret,work);
  37.       if(strlen(trashret)>3)           strcat(trashret,"\\HELP.FIC");
  38.       else                             strcat(trashret,"HELP.FIC");
  39.       if(pfhelp>0)                     close(pfhelp);
  40.       pfhelp=open(trashret,O_RDONLY | O_BINARY,S_IREAD|S_IWRITE);
  41.       if (pfhelp==-1){
  42.         textattr(colour5);               gotoxy(1,25);
  43.         cputs(" Can not open the help file ");   sound3();
  44.         wait_for_a_key();         return(0);
  45.       }
  46.       /* We put the file pointer approximatively at the location of */
  47.       /* the first help screen concerned by this call               */
  48.       /* If we passed 0, we put the pointer at the beginning of the */
  49.       /* file, else we go forward in the file 936 bytes further and */
  50.       /* this the number of necessary times. So we avoid a too long */
  51.       /* waiting because of the search of the first help screen in  */
  52.       /* the file.                                                  */
  53.       /* NB : 936 bytes is the size of an help screen.              */
  54.       if(offset==0)                   dephelp=0L;
  55.       else{
  56.         dephelp=offset*936L;
  57.       }
  58.       return(1);
  59.     }
  60.  /*------------*
  61.   * CHECK PAGE *
  62.   *------------*/
  63.   int check_page(page)
  64.     int page;
  65.     {
  66.       /* We check if the page number written in the help      */
  67.       /* screen is the good one.                              */
  68.       /* We do not modify file pointer, so we will not have   */
  69.       /* to correct it, but we go backward at 74 bytes of the */
  70.       /* beginning of this page                               */
  71.       dephelp+=112;                    nc1[3]=0x00;
  72.       lseek(pfhelp,dephelp,0);         read(pfhelp,nc1,3);
  73.       n=atoi(nc1);
  74.       dephelp-=112;                    lseek(pfhelp,dephelp,0);
  75.       if(n==page)                      return(1);
  76.       else                             return(0);
  77.    }
  78.  /*-------------------*
  79.   * FIND FIRST SCREEN *
  80.   *-------------------*/
  81.   int find_first_screen(refhelp,page)
  82.     char refhelp[9];
  83.     int page;
  84.     {
  85.       nc1[2]=0x00;                     lseek(pfhelp,dephelp,0);
  86.       while(!eof(pfhelp)){
  87.         read(pfhelp,trashhelp,8);       i=strcmp(trashhelp,refhelp);
  88.         /* If the header concern the asking, display it */
  89.     if(i==0){
  90.       if(page==0)                  return(1);
  91.       else{
  92.             k=check_page(page);
  93.         if(k==1)                   return(1);
  94.         else{
  95.               /* else we test the next screen */
  96.               dephelp+=936;            lseek(pfhelp,dephelp,0);
  97.         }
  98.       }
  99.     }
  100.     else{
  101.           /* else we test the next screen */
  102.           dephelp+=936;                lseek(pfhelp,dephelp,0);
  103.     }
  104.       }
  105.       /* If we are here that is because we are at the end of the file */
  106.       /* and we did not get the help screen : error                   */
  107.       if(pfhelp>0)                     close(pfhelp);
  108.       pfhelp=-1;                       sound3();
  109.       textattr(colour5);
  110.       gotoxy(41,4);           cputs("                                      ");
  111.       gotoxy(41,5);           cputs(" ╔══════════════════════════════════╗ ");
  112.       gotoxy(41,6);           cputs(" ║ Sorry. No help for this subject. ║ ");
  113.       gotoxy(41,7);           cputs(" ║      Press any Key to quit       ║ ");
  114.       gotoxy(41,8);           cputs(" ╚══════════════════════════════════╝ ");
  115.       gotoxy(41,9);           cputs("                                      ");
  116.       wait_for_a_key();           return(0);
  117.     }
  118.  /*----------------------*
  119.   * DISPLAY HELP SCREEN *
  120.   *----------------------*/
  121.   void display_help_screen()
  122.     {
  123.       /* Hide the mouse during the display */
  124.       hide_the_mouse();               textattr(colour3);
  125.       /* We choose to display the help screen on the right of the screen */
  126.       /* over the help menu to make understand that those menus are not  */
  127.       /* available during the consultation of the help                   */
  128.       for(i=2; i<25; i++){
  129.         dephelp+=39;
  130.         lseek(pfhelp,dephelp,0);       read(pfhelp,trashelhelp,39);
  131.         gotoxy(42,i);                  cputs(trashelhelp);
  132.       }
  133.       /* Put the file pointer on the first line  */
  134.       /* And show the mouse                      */
  135.       dephelp-=897;                    show_the_mouse();
  136.       if(beginningfile==1){
  137.         sound3();                        textattr(colour5);
  138.         gotoxy(44,2);                 cputs("  ATTENTION: beginning of help  ");
  139.         beginningfile=0;                    endfile=0;
  140.       }
  141.       if(endfile==1){
  142.         sound3();                        textattr(colour5);
  143.         gotoxy(44,2);                  cputs("  ATTENTION: end of help  ");
  144.         beginningfile=0;                    endfile=0;
  145.       }
  146.     }
  147.  /*-----------------------*
  148.   * CHOICE FOLLOWING HELP *
  149.   *-----------------------*/
  150.   int choice_following_help()
  151.     {
  152.     /* Waiting for a key or a mouse button */
  153.       while(1){
  154.     if(kbhit()){
  155.           /* If we pressed a key */
  156.       c1=getch();
  157.       if(c1>0){
  158.             /* We pressed a standard key */
  159.         if((c1==32)||(c1==13)||(c1==67)||(c1==99)){
  160.               /* <Space> <Enter> <C> <c> Next page */
  161.           return(1);
  162.         }
  163.         if((c1==8)||(c1==82)||(c1==114)){
  164.               /* <Back space> <R> <r> Previous page */
  165.           return(2);
  166.         }
  167.         if((c1==27)||(c1==81)||(c1==113)){
  168.               /* <Esc> <Q> <q> quit */
  169.           return(3);
  170.         }
  171.       }
  172.       else{
  173.             /* key code on 2 bytes */
  174.         c1=getch();
  175.         if((c1==77)||(c1==80)){
  176.               /* Right or Down arrow : Next page */
  177.           return(1);
  178.         }
  179.         if((c1==75)||(c1==72)){
  180.               /* Up or Left arrow = Previous page */
  181.           return(2);
  182.         }
  183.       }
  184.     }
  185.         /* Else test the mouse */
  186.         get_mouse_state();
  187.     if(bm==1){
  188.           /* We pressed a mouse button */
  189.       if((ym>21)&&(ym<25)){
  190.         if((xm>42)&&(xm<56))       return(1);
  191.         if((xm>56)&&(xm<68))       return(2);
  192.         if((xm>68)&&(xm<80))       return(3);
  193.       }
  194.           /* If we clicked on another line or outside the reserved zone */
  195.           /* quit help */
  196.           return(3);
  197.     }
  198.       }
  199.     }
  200.  /*--------------*
  201.   * DISPLAY HELP *
  202.   *--------------*/
  203.   void display_help(refhelp,offset,page,nbpages)
  204.     char refhelp[9];
  205.     int offset,page,nbpages;
  206.     {
  207.       pagemaxi=page+nbpages-1;
  208.       save_help_screen();         i=open_help_file(offset);
  209.       if(i==0){
  210.         hide_the_mouse();             restore_help_screen();
  211.         show_the_mouse();             return;
  212.       }
  213.       trashhelp[8]=0x00;                refhelp[8]=0x00;
  214.       trashelhelp[39]=0x00;             i=find_first_screen(refhelp,page);
  215.       if(i==0){
  216.         hide_the_mouse();             restore_help_screen();
  217.         show_the_mouse();            return;
  218.       }
  219.       beginningfile=0;                     endfile=0;
  220.       depbeginning=dephelp;                lseek(pfhelp,dephelp,0);
  221.       while(!eof(pfhelp)){
  222.         read(pfhelp,trashhelp,8);       i=strcmp(trashhelp,refhelp);
  223.         /* If the screen matches, we display it after verifying that */
  224.         /* if required, the page number matches too                  */
  225.     if(i==0){
  226.           if(page==0)                  display_help_screen();
  227.       else{
  228.             k=check_page(page);
  229.             if(k==1)                   display_help_screen();
  230.         else{
  231.               /* Else we are after the last page */
  232.               endfile=1;                dephelp-=936;
  233.               display_help_screen();
  234.         }
  235.       }
  236.     }
  237.     else{
  238.           /* If the header does not match anymore, we are at the end   */
  239.           /* we note this end, we display this. Then we go back to the */
  240.           /* previous screen                                           */
  241.           endfile=1;                    dephelp-=936;
  242.           display_help_screen();
  243.     }
  244.         /* If there are several pages, we increment */
  245.     if(page>0){
  246.           /* We precised one or more pages */
  247.       if(page<pagemaxi)            page++;
  248.     }
  249.         /* We wait the user's choice */
  250.         /* 1 Next page, 2 Previous page, 3 Quit */
  251.         j=choice_following_help();
  252.         /* If we go on with the next screen */
  253.         if(j==1)                       dephelp+=936;
  254.     if(j==2){
  255.           /* If we want to go back to the previous screen */
  256.           dephelp-=936;
  257.           if(dephelp<0){
  258.             /* We are before the header */
  259.             dephelp=0L;                beginningfile=1;
  260.       }
  261.           if(dephelp<=depbeginning){
  262.             /* We are back before the beginning of the first screen */
  263.             /* that concerns the wanted help */
  264.             dephelp=depbeginning;          beginningfile=1;
  265.       }
  266.     }
  267.     if(j==3){
  268.           /* If we want to quit */
  269.           if(pfhelp>0)                 close(pfhelp);
  270.           pfhelp=-1;
  271.           hide_the_mouse();           restore_help_screen();
  272.           show_the_mouse();          return;
  273.     }
  274.         lseek(pfhelp,dephelp,0);
  275.         if(eof(pfhelp)){
  276.           /* We note the end of the file and we put the file pointer */
  277.           /* to the beginning of the last valid screen               */
  278.           dephelp-=936;                lseek(pfhelp,dephelp,0);
  279.           endfile=1;
  280.     }
  281.       }
  282.     }
  283. /* End of the main program supplement  */
  284.